import trainApi from 'api/train'
// import { countArr } from 'utils'
let state = {
  train_school_list: [],
  train_currilum_list: [], // 课程列表数据
  train_class_list: [], // 班级列表数据
  train_teacher_list: [], // 所有教练数据
  train_selectclass_list: [], // 所有课程下拉列表
  train_coach_list: [], // 教练列表
  train_coach_course: [], // 教练授课课程
  train_coach_info: [], // 教练信息
  country_list: [], // 国家列表
  train_student_list: [], // 学员列表
  train_student_detail: {}, // 学员详情
  train_student_course_list: [], // 获取学员在上课程列表
  train_student_info: [], // 获取编辑的学员信息
  train_student_course_info: [], // 获取上课情况信息
  train_student_course: [], // 获取学员详情上课情况列表
  train_scholl_type_list: [], // 根据课程ID获取校区数据
  train_class_type_list: [], // 根据课程ID获取班别数据
  train_class_student: [], // 班级学员列表
  train_class_studentCK: [], // 次课班级学员列表
  train_student_vacate: [], // 根据学员ID获取请假课时信息
  train_student_close_vacate: [], // 根据学员ID获取撤销请假课时信息
  train_course_time_count: [],
  train_course_campus_class: [], // 获取课程校区班别
  train_student_make_up: [], // 获取学员补课中的缺课信息
  train_makeup__course_info: [], // 获取学员补课课程的课时信息
  train_coach_course_time: [], // 获取教练未请假课时
  train_coach_leave_time: [], // 获取教练需要撤销请假课时,
  train_teacher_info: {}, // 授权
  train_student_history_course: [], // 学员详情历史课程
  train_student_signup: {}, // 班级学员导入列表
  train_student_renew_num: '', // 学员续费总数
  train_ck_course_list: [], // 获取次课类型
  train_sale_name: '',
  train_compus_selection: {}, // 班级学员导入列表
  train_student_dispose_list: [],
  train_student_test_list: [], // 学员测试成绩列表
  train_standard_rules_list: {}, // 测试成绩查看评分标准
  train_body_data: [], // 学员身体数据
  train_freeze_detail: {}, // 冻结详情
  train_body_data_category: [], // 学员身体数据类别
  train_adviser_list: [] // 顾问列表
}

const getters = {
  train_currilum_list: state => state.train_currilum_list,
  train_class_list: state => state.train_class_list,
  train_teacher_list: state => state.train_teacher_list,
  train_selectclass_list: state => state.train_selectclass_list,
  train_coach_list: state => state.train_coach_list,
  train_coach_course: state => state.train_coach_course,
  train_coach_info: state => state.train_coach_info,
  country_list: state => state.country_list,
  train_student_list: state => state.train_student_list,
  train_student_detail: state => state.train_student_detail,
  train_student_course_list: state => state.train_student_course_list,
  train_student_info: state => state.train_student_info,
  train_student_course_info: state => state.train_student_course_info,
  train_student_course: state => state.train_student_course,
  train_scholl_type_list: state => state.train_scholl_type_list,
  train_class_type_list: state => state.train_class_type_list,
  train_class_student: state => state.train_class_student,
  train_class_studentCK: state => state.train_class_studentCK,
  train_student_vacate: state => state.train_student_vacate,
  train_student_close_vacate: state => state.train_student_close_vacate,
  train_course_time_count: state => state.train_course_time_count,
  train_course_campus_class: state => state.train_course_campus_class,
  train_student_make_up: state => state.train_student_make_up,
  train_makeup__course_info: state => state.train_makeup__course_info,
  train_coach_course_time: state => state.train_coach_course_time,
  train_coach_leave_time: state => state.train_coach_leave_time,
  train_teacher_info: state => state.train_teacher_info,
  train_student_history_course: state => state.train_student_history_course,
  train_student_signup: state => state.train_student_signup,
  train_school_list: state => state.train_school_list,
  train_student_renew_num: state => state.train_student_renew_num,
  train_ck_course_list: state => state.train_ck_course_list,
  train_sale_name: state => state.train_sale_name,
  train_compus_selection: state => state.train_compus_selection,
  train_student_dispose_list: state => state.train_student_dispose_list,
  train_student_test_list: state => state.train_student_test_list,
  train_standard_rules_list: state => state.train_standard_rules_list,
  train_body_data: state => state.train_body_data,
  train_freeze_detail: state => state.train_freeze_detail,
  train_body_data_category: state => state.train_body_data_category,
  train_adviser_list: state => state.train_adviser_list
}

const actions = {
  train_currilum_list ({commit, state}, params) {
    trainApi.getListCurrculum(params).then((json) => {
      commit('TRAIN_CURRILUM_LIST', json.data)
    })
  },
  train_class_list ({commit, state}, params) {
    trainApi.listPageInfo(params).then((json) => {
      commit('TRAIN_CLASS_LIST', json.data)
    })
  },
  train_teacher_list ({commit, state}) {
    trainApi.teacherList().then((json) => {
      commit('TRAIN_TEACHER_LIST', json.data)
    })
  },
  train_selectclass_list ({commit, state}) {
    trainApi.classList().then((json) => {
      commit('TRAIN_SELECTCLASS_LIST', json.data)
    })
  },
  train_coach_list ({commit, state}, params) {
    state.train_coach_list = {}
    trainApi.coachList(params).then((json) => {
      commit('TRAIN_COACH_LIST', json.data)
    })
  },
  train_coach_course ({commit, state}, params) {
    trainApi.coachCourseDetail(params).then((json) => {
      commit('TRAIN_COACH_COURSE', json.data)
    })
  },
  train_coach_info ({commit, state}, params) {
    trainApi.coachInfo(params).then((json) => {
      commit('TRAIN_COACH_INFO', json.data)
    })
  },
  country_list ({commit, state}, params) {
    trainApi.countryList(params).then((json) => {
      commit('COUNTRY_LIST', json.data)
    })
  },
  train_student_list ({commit, state}, params) {
    state.train_student_list = {}
    trainApi.studentList(params).then((json) => {
      commit('TRAIN_STUDENT_LIST', json.data)
    })
  },
  train_student_detail ({commit, state}, params) {
    trainApi.studentDetail(params).then((json) => {
      commit('TRAIN_STUDENT_DETAIL', json.data)
    })
  },
  train_student_course_list ({commit, state}, params) {
    state.train_student_course_list = {}
    trainApi.studentCourseList(params).then((json) => {
      commit('TRAIN_STUDENT_COURSE_LIST', json.data)
    })
  },
  train_student_info ({commit, state}, params) {
    trainApi.studentInfo(params).then((json) => {
      commit('TRAIN_STUDENT_INFO', json.data)
    })
  },
  train_student_course_info ({commit, state}, params) {
    trainApi.studentCourseInfo(params).then((json) => {
      commit('TRAIN_STUDENT_COURSE_INFO', json.data)
    })
  },
  train_student_course ({commit, state}, params) {
    trainApi.studentCourse(params).then((json) => {
      commit('TRAIN_STUDENT_COURSE', json.data)
    })
  },
  train_scholl_type_list ({commit, state}, params) {
    state.train_scholl_type_list = []
    trainApi.getSchoolList(params).then((json) => {
      commit('TRAIN_SCHOLL_TYPE_LIST', json.data)
    })
  },
  train_class_type_list ({commit, state}, params) {
    state.train_class_type_list = []
    trainApi.getClasstypeList(params).then((json) => {
      commit('TRAIN_CLASS_TYPE_LIST', json.data)
    })
  },
  train_class_student ({commit, state}, params) {
    trainApi.classStudentInfo(params).then((json) => {
      commit('TRAIN_CLASS_STUDENT', json.data)
    })
  },
  train_class_studentCK ({commit, state}, params) {
    trainApi.classStudentInfoByCK(params).then((json) => {
      commit('TRAIN_CLASS_STUDENTCK', json.data)
    })
  },
  train_student_vacate ({commit, state}, params) {
    trainApi.studentVacate(params).then((json) => {
      commit('TRAIN_STUDENT_VACATE', json.data)
    })
  },
  train_student_close_vacate ({commit, state}, params) {
    trainApi.studentCloseVacate(params).then((json) => {
      commit('TRAIN_STUDENT_CLOSE_VACATE', json.data)
    })
  },
  train_course_time_count ({commit, state}, params) {
    trainApi.courseTimeCount(params).then((json) => {
      commit('TRAIN_COURSE_TIME_COUNT', json.data)
    })
  },
  train_course_campus_class ({commit, state}, params) {
    trainApi.courseCampusClass(params).then((json) => {
      commit('TRAIN_COURSE_CAMPUS_CLASS', json.data)
    })
  },
  train_student_make_up ({commit, state}, params) {
    trainApi.studentMakeUp(params).then((json) => {
      commit('TRAIN_STUDENT_MAKE_UP', json.data)
    })
  },
  train_makeup__course_info ({commit, state}, params) {
    trainApi.courseInfo(params).then((json) => {
      commit('TRAIN_STUDENT_MAKEUP_COURSE_INFO', json.data)
    })
  },
  train_coach_course_time ({commit, state}, params) {
    trainApi.coachCourseTime(params).then((json) => {
      commit('TRAIN_COACH_COURSE_TIME', json.data)
    })
  },
  train_coach_leave_time ({commit, state}, params) {
    trainApi.coachLeaveCourseTime(params).then((json) => {
      commit('TRAIN_COACH_LEAVE_TIME', json.data)
    })
  },
  train_teacher_info ({commit, state}, params) {
    trainApi.getThisTeacherInfo(params).then((json) => {
      commit('TRAIN_TEACHER_INFO', json.data)
    })
  },
  train_student_history_course ({commit, state}, params) {
    trainApi.getStudentHistoryCourse(params).then((json) => {
      commit('TRAIN_STUDENT_HISTORY_COURSE', json.data)
    })
  },
  train_student_signup ({commit, state}, params) {
    state.train_student_signup = {}
    trainApi.studentSignUp(params).then((json) => {
      commit('TRAIN_STUDENT_SIGNUP', json.data)
    })
  },
  train_school_list ({commit, state}, params) {
    trainApi.schoolList(params).then((json) => {
      commit('TRAN_SCHOOL_LIST', json.data.list)
    })
  },
  train_student_renew_num ({commit, state}, params) {
    trainApi.renewNum(params).then((json) => {
      commit('TRAIN_STUDENT_RENEW_NUM', json.data)
    })
  },
  train_ck_course_list ({commit, state}, params) {
    trainApi.queryTimeCourse(params).then((json) => {
      commit('TRAIN_CK_COURSE_LIST', json.data)
    })
  },
  train_compus_selection ({commit, state}, params) {
    trainApi.querySelection(params).then((json) => {
      commit('TRAIN_COMPUS_SELECTION', json.data)
    })
  },
  train_student_dispose_list ({commit, state}, params) {
    trainApi.studentCkDisposeList(params).then((json) => {
      commit('TRAIN_STUDENT_DISPOSE_LIST', json.data)
    })
  },
  train_student_test_list ({commit, state}, params) {
    trainApi.studentTestList(params).then((json) => {
      commit('TRAIN_STUDENT_TEST_LIST', json.data)
    })
  },
  train_standard_rules_list ({commit, state}, params) {
    state.train_standard_rules_list = {}
    trainApi.standardRules(params).then((json) => {
      commit('TRAIN_STANDARD_RULES_LIST', json.data)
    })
  },
  train_freeze_detail ({commit, state}, params) {
    trainApi.freezeDetail(params).then((json) => {
      commit('TRAIN_FREEZE_DETAIL', json.data)
    })
  },
  train_adviser_list ({commit, state}, params) {
    trainApi.getAdviserList(params).then((json) => {
      commit('TRAIN_ADVISER_LIST', json.data)
    })
  }
}

const mutations = {
  TRAIN_CURRILUM_LIST (state, data) {
    state.train_currilum_list = data
  },
  TRAIN_CLASS_LIST (state, data) {
    state.train_class_list = data
  },
  TRAIN_TEACHER_LIST (state, data) {
    state.train_teacher_list = data
  },
  TRAIN_SELECTCLASS_LIST (state, data) {
    state.train_selectclass_list = data
  },
  TRAIN_COACH_LIST (state, data) {
    state.train_coach_list = data
  },
  TRAIN_COACH_COURSE (state, data) {
    state.train_coach_course = data
  },
  TRAIN_COACH_INFO (state, data) {
    state.train_coach_info = data
  },
  COUNTRY_LIST (state, data) {
    state.country_list = data
  },
  TRAIN_STUDENT_LIST (state, data) {
    state.train_student_list = data
  },
  TRAIN_STUDENT_DETAIL (state, data) {
    state.train_student_detail = data
  },
  TRAIN_STUDENT_COURSE_LIST (state, data) {
    state.train_student_course_list = data
  },
  TRAIN_STUDENT_INFO (state, data) {
    data.locationOrigin = [data.locationProvinceId, data.locationCityId]
    state.train_student_info = data
  },
  TRAIN_STUDENT_COURSE_INFO (state, data) {
    state.train_student_course_info = data
  },
  TRAIN_STUDENT_COURSE (state, data) {
    state.train_student_course = data
  },
  TRAIN_SCHOLL_TYPE_LIST (state, data) {
    state.train_scholl_type_list = data
  },
  TRAIN_CLASS_TYPE_LIST (state, data) {
    state.train_class_type_list = data
  },
  TRAIN_CLASS_STUDENT (state, data) {
    state.train_class_student = data
  },
  TRAIN_CLASS_STUDENTCK (state, data) {
    state.train_class_studentCK = data
  },
  TRAIN_STUDENT_VACATE (state, data) {
    state.train_student_vacate = data
  },
  TRAIN_STUDENT_CLOSE_VACATE (state, data) {
    state.train_student_close_vacate = data
  },
  TRAIN_COURSE_TIME_COUNT (state, data) {
    state.train_course_time_count = data
  },
  TRAIN_COURSE_CAMPUS_CLASS (state, data) {
    state.train_course_campus_class = data
  },
  TRAIN_STUDENT_MAKE_UP (state, data) {
    state.train_student_make_up = data
  },
  TRAIN_STUDENT_MAKEUP_COURSE_INFO (state, data) {
    state.train_makeup__course_info = data
  },
  TRAIN_COACH_COURSE_TIME (state, data) {
    state.train_coach_course_time = data
  },
  TRAIN_COACH_LEAVE_TIME (state, data) {
    state.train_coach_leave_time = data
  },
  TRAIN_TEACHER_INFO (state, data) {
    state.train_teacher_info = data
  },
  TRAIN_STUDENT_HISTORY_COURSE (state, data) {
    state.train_student_history_course = data
  },
  TRAIN_STUDENT_SIGNUP (state, data) {
    state.train_student_signup = data
  },
  TRAN_SCHOOL_LIST (state, data) {
    state.train_school_list = data
  },
  TRAIN_STUDENT_RENEW_NUM (state, data) {
    state.train_student_renew_num = data
  },
  TRAIN_CK_COURSE_LIST (state, data) {
    state.train_ck_course_list = data
  },
  TRAN_SALE_NAME (state, payload) {
    state.train_sale_name = payload
  },
  TRAIN_COMPUS_SELECTION (state, data) {
    state.train_compus_selection = data
  },
  TRAIN_STUDENT_DISPOSE_LIST (state, data) {
    state.train_student_dispose_list = data
  },
  TRAIN_STUDENT_TEST_LIST (state, data) {
    if (data.list && data.list.length) {
      data.list = data.list.map(item => {
        return Object.assign({isEdit: false}, item)
      })
    }
    state.train_student_test_list = data
  },
  TRAIN_STANDARD_RULES_LIST (state, data) {
    state.train_standard_rules_list = data
  },
  TRAIN_BODY_DATA (state, data) {
    state.train_body_data = data
  },
  TRAIN_FREEZE_DETAIL (state, data) {
    state.train_freeze_detail = data
  },
  TRAIN_BODY_DATA_CATEGORY (state, data) {
    state.train_body_data_category = data
  },
  TRAIN_ADVISER_LIST (state, data) {
    state.train_adviser_list = data
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}
